#pragma once
#include <iostream>
#include <fstream>
#include<graphics.h>
namespace dm {

	double normaldist(double sigma, double x) 
	{
		return exp( -(x / (2 * sigma * sigma))) / (sigma * sqrt(2 * 3.1415926));
	}

	using std::ifstream;
	double defaultMT[] = 
						 { 1,1,1,
						   1,1,1,
						   1,1,1 };
	double* defaultCK;
	double coefficient[] = {0,0,0,0};
	int isCKInit=0;
	int KernelSize = 7;
	int KernelLength = 15*15;
	double sigma = 1;
	double pixelSize = 1;
	double stepLength = 1;
	void ChangeMT() {
		ifstream file = ifstream("./Matrix.txt");
		bool success=file.is_open();
		file >> dm::defaultMT[0];
		file >> dm::defaultMT[1];
		file >> dm::defaultMT[2];
		file >> dm::defaultMT[3];
		file >> dm::defaultMT[4];
		file >> dm::defaultMT[5];
		file >> dm::defaultMT[6];
		file >> dm::defaultMT[7];
		file >> dm::defaultMT[8];
		file >> stepLength;
		file.close();
	}
	void ChangeCK() {
		ifstream file = ifstream("./Kernel.txt");
		bool success = file.is_open();
		int update;
		file >> update;
		if (update||(!(isCKInit))) {
			file >> KernelSize;
			file >> sigma;
			file >> pixelSize;
			KernelLength = (KernelSize * 2 + 1) * (KernelSize * 2 + 1);
			delete[] defaultCK;
			defaultCK = new double[KernelLength];
			for (int kxi = -KernelSize; kxi <= KernelSize; kxi++) {
				for (int kyi = -KernelSize; kyi <= KernelSize; kyi++) {
					int i = ((kyi + KernelSize) * (KernelSize*2+1)) + kxi + KernelSize;
					defaultCK[i]=normaldist(sigma,kxi*pixelSize*kxi*pixelSize+kyi*pixelSize*kyi*pixelSize);
					//defaultCK[((kyi + KernelSize) * KernelSize) + kxi + KernelSize] = 1;
				}
			}
			isCKInit = 1;
		}
		file.close();

	}
	void ChangeC() {
		ifstream file = ifstream("./Coefficient.txt");
		bool success = file.is_open();
		file >> dm::coefficient[0];
		file >> dm::coefficient[1];
		file >> dm::coefficient[2];
		file >> dm::coefficient[3];
		file.close();
	}
}